1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.ShortcutTrigger;
26 
27 private import gdk.Display;
28 private import gdk.Event;
29 private import glib.ConstructionException;
30 private import glib.Str;
31 private import glib.StringG;
32 private import glib.c.functions;
33 private import gobject.ObjectG;
34 private import gtk.c.functions;
35 public  import gtk.c.types;
36 
37 
38 /**
39  * `GtkShortcutTrigger` tracks how a `GtkShortcut` should be activated.
40  * 
41  * To find out if a `GtkShortcutTrigger` triggers, you can call
42  * [method@Gtk.ShortcutTrigger.trigger] on a `GdkEvent`.
43  * 
44  * `GtkShortcutTriggers` contain functions that allow easy presentation
45  * to end users as well as being printed for debugging.
46  * 
47  * All `GtkShortcutTriggers` are immutable, you can only specify their
48  * properties during construction. If you want to change a trigger, you
49  * have to replace it with a new one.
50  */
51 public class ShortcutTrigger : ObjectG
52 {
53 	/** the main Gtk struct */
54 	protected GtkShortcutTrigger* gtkShortcutTrigger;
55 
56 	/** Get the main Gtk struct */
57 	public GtkShortcutTrigger* getShortcutTriggerStruct(bool transferOwnership = false)
58 	{
59 		if (transferOwnership)
60 			ownedRef = false;
61 		return gtkShortcutTrigger;
62 	}
63 
64 	/** the main Gtk struct as a void* */
65 	protected override void* getStruct()
66 	{
67 		return cast(void*)gtkShortcutTrigger;
68 	}
69 
70 	/**
71 	 * Sets our main struct and passes it to the parent class.
72 	 */
73 	public this (GtkShortcutTrigger* gtkShortcutTrigger, bool ownedRef = false)
74 	{
75 		this.gtkShortcutTrigger = gtkShortcutTrigger;
76 		super(cast(GObject*)gtkShortcutTrigger, ownedRef);
77 	}
78 
79 
80 	/** */
81 	public static GType getType()
82 	{
83 		return gtk_shortcut_trigger_get_type();
84 	}
85 
86 	/**
87 	 * Tries to parse the given string into a trigger.
88 	 *
89 	 * On success, the parsed trigger is returned.
90 	 * When parsing failed, %NULL is returned.
91 	 *
92 	 * The accepted strings are:
93 	 *
94 	 * - `never`, for `GtkNeverTrigger`
95 	 * - a string parsed by gtk_accelerator_parse(), for a `GtkKeyvalTrigger`, e.g. `<Control>C`
96 	 * - underscore, followed by a single character, for `GtkMnemonicTrigger`, e.g. `_l`
97 	 * - two valid trigger strings, separated by a `|` character, for a
98 	 * `GtkAlternativeTrigger`: `<Control>q|<Control>w`
99 	 *
100 	 * Note that you will have to escape the `<` and `>` characters when specifying
101 	 * triggers in XML files, such as GtkBuilder ui files. Use `&lt;` instead of
102 	 * `<` and `&gt;` instead of `>`.
103 	 *
104 	 * Params:
105 	 *     string_ = the string to parse
106 	 *
107 	 * Returns: a new `GtkShortcutTrigger`
108 	 *
109 	 * Throws: ConstructionException GTK+ fails to create the object.
110 	 */
111 	public this(string string_)
112 	{
113 		auto __p = gtk_shortcut_trigger_parse_string(Str.toStringz(string_));
114 
115 		if(__p is null)
116 		{
117 			throw new ConstructionException("null returned by parse_string");
118 		}
119 
120 		this(cast(GtkShortcutTrigger*) __p, true);
121 	}
122 
123 	/**
124 	 * The types of @trigger1 and @trigger2 are `gconstpointer` only to allow
125 	 * use of this function as a `GCompareFunc`.
126 	 *
127 	 * They must each be a `GtkShortcutTrigger`.
128 	 *
129 	 * Params:
130 	 *     trigger2 = a `GtkShortcutTrigger`
131 	 *
132 	 * Returns: An integer less than, equal to, or greater than zero if
133 	 *     @trigger1 is found, respectively, to be less than, to match,
134 	 *     or be greater than @trigger2.
135 	 */
136 	public int compare(ShortcutTrigger trigger2)
137 	{
138 		return gtk_shortcut_trigger_compare(gtkShortcutTrigger, (trigger2 is null) ? null : trigger2.getShortcutTriggerStruct());
139 	}
140 
141 	/**
142 	 * Checks if @trigger1 and @trigger2 trigger under the same conditions.
143 	 *
144 	 * The types of @one and @two are `gconstpointer` only to allow use of this
145 	 * function with `GHashTable`. They must each be a `GtkShortcutTrigger`.
146 	 *
147 	 * Params:
148 	 *     trigger2 = a `GtkShortcutTrigger`
149 	 *
150 	 * Returns: %TRUE if @trigger1 and @trigger2 are equal
151 	 */
152 	public bool equal(ShortcutTrigger trigger2)
153 	{
154 		return gtk_shortcut_trigger_equal(gtkShortcutTrigger, (trigger2 is null) ? null : trigger2.getShortcutTriggerStruct()) != 0;
155 	}
156 
157 	/**
158 	 * Generates a hash value for a `GtkShortcutTrigger`.
159 	 *
160 	 * The output of this function is guaranteed to be the same for a given
161 	 * value only per-process. It may change between different processor
162 	 * architectures or even different versions of GTK. Do not use this
163 	 * function as a basis for building protocols or file formats.
164 	 *
165 	 * The types of @trigger is `gconstpointer` only to allow use of this
166 	 * function with `GHashTable`. They must each be a `GtkShortcutTrigger`.
167 	 *
168 	 * Returns: a hash value corresponding to @trigger
169 	 */
170 	public uint hash()
171 	{
172 		return gtk_shortcut_trigger_hash(gtkShortcutTrigger);
173 	}
174 
175 	/**
176 	 * Prints the given trigger into a string for the developer.
177 	 * This is meant for debugging and logging.
178 	 *
179 	 * The form of the representation may change at any time
180 	 * and is not guaranteed to stay identical.
181 	 *
182 	 * Params:
183 	 *     string_ = a `GString` to print into
184 	 */
185 	public void print(StringG string_)
186 	{
187 		gtk_shortcut_trigger_print(gtkShortcutTrigger, (string_ is null) ? null : string_.getStringGStruct());
188 	}
189 
190 	/**
191 	 * Prints the given trigger into a string.
192 	 *
193 	 * This function is returning a translated string for presentation
194 	 * to end users for example in menu items or in help texts.
195 	 *
196 	 * The @display in use may influence the resulting string in
197 	 * various forms, such as resolving hardware keycodes or by
198 	 * causing display-specific modifier names.
199 	 *
200 	 * The form of the representation may change at any time and is
201 	 * not guaranteed to stay identical.
202 	 *
203 	 * Params:
204 	 *     display = `GdkDisplay` to print for
205 	 *     string_ = a `GString` to print into
206 	 *
207 	 * Returns: %TRUE if something was printed or %FALSE if the
208 	 *     trigger did not have a textual representation suitable
209 	 *     for end users.
210 	 */
211 	public bool printLabel(Display display, StringG string_)
212 	{
213 		return gtk_shortcut_trigger_print_label(gtkShortcutTrigger, (display is null) ? null : display.getDisplayStruct(), (string_ is null) ? null : string_.getStringGStruct()) != 0;
214 	}
215 
216 	/**
217 	 * Gets textual representation for the given trigger.
218 	 *
219 	 * This function is returning a translated string for
220 	 * presentation to end users for example in menu items
221 	 * or in help texts.
222 	 *
223 	 * The @display in use may influence the resulting string in
224 	 * various forms, such as resolving hardware keycodes or by
225 	 * causing display-specific modifier names.
226 	 *
227 	 * The form of the representation may change at any time and is
228 	 * not guaranteed to stay identical.
229 	 *
230 	 * Params:
231 	 *     display = `GdkDisplay` to print for
232 	 *
233 	 * Returns: a new string
234 	 */
235 	public string toLabel(Display display)
236 	{
237 		auto retStr = gtk_shortcut_trigger_to_label(gtkShortcutTrigger, (display is null) ? null : display.getDisplayStruct());
238 
239 		scope(exit) Str.freeString(retStr);
240 		return Str.toString(retStr);
241 	}
242 
243 	/**
244 	 * Prints the given trigger into a human-readable string.
245 	 *
246 	 * This is a small wrapper around [method@Gtk.ShortcutTrigger.print]
247 	 * to help when debugging.
248 	 *
249 	 * Returns: a new string
250 	 */
251 	public override string toString()
252 	{
253 		auto retStr = gtk_shortcut_trigger_to_string(gtkShortcutTrigger);
254 
255 		scope(exit) Str.freeString(retStr);
256 		return Str.toString(retStr);
257 	}
258 
259 	/**
260 	 * Checks if the given @event triggers @self.
261 	 *
262 	 * Params:
263 	 *     event = the event to check
264 	 *     enableMnemonics = %TRUE if mnemonics should trigger. Usually the
265 	 *         value of this property is determined by checking that the passed
266 	 *         in @event is a Key event and has the right modifiers set.
267 	 *
268 	 * Returns: Whether the event triggered the shortcut
269 	 */
270 	public GdkKeyMatch trigger(Event event, bool enableMnemonics)
271 	{
272 		return gtk_shortcut_trigger_trigger(gtkShortcutTrigger, (event is null) ? null : event.getEventStruct(), enableMnemonics);
273 	}
274 }